<?php
/**
 * Created by PhpStorm.
 * User: User
 * Date: 2017/12/5
 * Time: 14:00
 */

namespace Kinfy\Facades;

use Kinfy\Config;

class Facade
{

    protected static $provider = '';
    protected static $instance = null;

    public static function __callStatic($name, $params)
    {


        if (!isset(self::$instance[static::$provider])) {
            $class = Config::get('app.providers.' . static::$provider);
            self::$instance[static::$provider] = new $class;

            $interface = '\Kinfy\Interfaces\I' . static::$provider;

            if (Config::get('app.provider_interface_check')
                &&
                !self::$instance[static::$provider] instanceof $interface) {
                die("{$class}类必须实现{$interface}接口");
            }
        }
        return self::$instance[static::$provider]->{$name}(...$params);
    }

}